import {defineStore} from "pinia";
import piniaPersistConfig from "@/stores/helper/persist";
import {getSelectProjectListApi} from "@/api/modules/project/projectManage.js";

export const useProjectStore = defineStore({
    id: "chestnut-project",
    state: () => ({
        currentProject: "",
        currentProjectId:"",
        selectProjectList: []
    }),
    actions: {
        async getSelectProjectList() {
            getSelectProjectListApi().then(res => {
                this.selectProjectList = res.data
                // 当前未选择项目，且可选项目有值的情况
                if (this.currentProject === "" && this.selectProjectList) {
                    this.currentProjectId = this.selectProjectList[0].id
                    this.currentProject = this.selectProjectList[0].project_name

                }
            })
        },
    },
    // 持久化数据存储
    persist: piniaPersistConfig("chestnut-project")
})
